<?php 

class LoginModel extends Model{
	public $table='admin';
	public function __init()
	{
		# code...
	}
	//验证用户登录
	public function userLogin()
	{
		if (empty($_POST['username'])) {
			$this->error='用户名不能为空';
			return false;
		}
		if (empty($_POST['password'])) {
			$this->error='密码不能为空';
			return false;
		}
		if (empty($_POST['code'])) {
			$this->error='验证码输入错误';
			return false;
		}
		$user=$this->where(" username='{$_POST['username']}'")->find();
		if (!$user) {
			$this->error='用户名不存在';
			return false;
		}
		if ($user['password']!=md5($_POST['password'].$user['code'])) {
			$this->error='密码输入错误';
			return false;
		}
		$code=Q('post.code','','strtoupper');
		if ($code!=$_SESSION['code']) {
			$this->error='验证码输入错误';
			return false;
		}
		unset($user['code']);
		unset($user['password']);
		$_SESSION['user']=$user;
		return true;
	}
}

 ?>